package com.sqy.utlis;


import com.sqy.exception.ImoocMallExceptionEnum;


public class ApiResult<T> {
    private Integer status;
    private String msg;
    private T data;

    private static final int OK_CODE = 10000;

    private static final String OK_MSG = "SUCCESS";

    private static final  Object OBJECT = null;

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public ApiResult(Integer status, String msg, T data) {
        this.status = OK_CODE;
        this.msg = OK_MSG;
        this.data = (T) data;
    }
    public ApiResult(T data){
         this.msg=OK_MSG;
         this.status=OK_CODE;
        this.data=data;
    }

    public ApiResult(Integer status, String msg) {
        this.status = status;
        this.msg = msg;
    }

    public ApiResult() {

        this(OK_CODE, OK_MSG);
    }

    public static <T> ApiResult<T> success() {
        return new ApiResult<>();
    }

    public static <T> ApiResult<T> success(T result) {
        ApiResult<T> response = new ApiResult<>();
        response.setData(result);
        return response;
    }

    public static <T> ApiResult<T> error(ImoocMallExceptionEnum exceptionEnum) {

        return new ApiResult<>(exceptionEnum.getCode(),exceptionEnum.getMsg());
    }
    public static <T> ApiResult<T> error(Integer status,String msg) {

        return new ApiResult<>(status,msg);
    }

    @Override
    public String toString() {
        return "ApiResult{" +
                "status=" + status +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                '}';
    }
}
